package me.jiatao.baselibrary.rx

import io.reactivex.Observable
import me.jiatao.baselibrary.common.ResultCode
import me.jiatao.baselibrary.data.protocol.HttpResult
import me.jiatao.baselibrary.exception.BaseException
import io.reactivex.functions.Function

/**
 *  Boolean类型转换封装
 */
class BaseFuncBoolean<T> : Function<HttpResult<T>, Observable<Boolean>> {
    override fun apply(t: HttpResult<T>): Observable<Boolean> {
        if (t.errorCode != ResultCode.SUCCESS) {
            return Observable.error(BaseException(t.errorCode, t.errorMsg))
        }

        return Observable.just(true)
    }
}
